/**
 * 2016，thor.com，all rights reserved。
 * 
 * Project：		palmmall-core
 * Filename：	SComplaintConverter.java
 * Created：		2016年8月21日
 * Creator：		wolv
 */
package com.thor.palmmall.rest.device.repair.converter;

import java.util.ArrayList;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.UCN;
import com.thor.palmmall.rest.device.repair.ADeviceRepairConfig;
import com.thor.palmmall.spi.device.repair.SDeviceRepairConfig;

/**
 * @author wolv
 *
 */
public class ADeviceRepairConfigConverter
    implements Converter<SDeviceRepairConfig, ADeviceRepairConfig> {

  public static ADeviceRepairConfigConverter getInstance() {
    if (instance == null)
      instance = new ADeviceRepairConfigConverter();
    return instance;
  }

  private static ADeviceRepairConfigConverter instance;

  private ADeviceRepairConfigConverter() {
  }

  @Override
  public ADeviceRepairConfig convert(SDeviceRepairConfig source) {
    if (source == null)
      return null;

    ADeviceRepairConfig target = new ADeviceRepairConfig();
    target.setBuckleInventory(source.getBuckleInventory());
    target.setWarehouse(UCN.newInstance(source.getWarehouse()));
    target.setRoles(new ArrayList<String>());
    if (source.getRoles() != null)
      target.getRoles().addAll(source.getRoles());

    return target;
  }
}
